<?php

class Application_Form_Projects extends EW_Form_DbObject {
    
    /**
     * @see EW_Form_DbObject::_beforeSave()
     */
    protected function _beforeSave() {}
    
    /**
     * 
     * @see EW_Form_DbObject::_afterSave()
     */
    protected function _afterSave() {
        $this->_controller->redirectTo('/projects');
    }
    //================================================================================
    
    protected function _initialize() {
        /*
        // Set the action for this form
        $this->setAction('/projects/save');
        */
        
        // Set the method for the display form to POST
        $this->setMethod(self::METHOD_POST);
        
        
        /**
         * Hidden Fields
         */
        $this->addElement('hidden', 'id', array('value'=>0));
        
        // Add an title element
        $this->addElement('text', 'title', array(
            'label'      => 'Title:',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array()
        ));
 
        // Add the submit button
        $this->addElement('submit', 'submit', array(
            'ignore'   => true,
            'label'    => 'Save',
        ));
        
		/*
        // And finally add some CSRF protection
        $this->addElement('hash', 'csrf', array(
            'ignore' => true,
        ));
        */
    }
    //================================================================================

    /**
     * Initialize decorators
     */
    protected function _initDecorators() {
        // Element decorators
        $this->setElementDecorators(array(
            array('Label', array('class' => 'text-info')),
            'ViewHelper',
            array('HtmlTag', array('tag' => 'br', 'class' => 'clear')),
            'Errors',
        ));

        // Only ViewHelper for submit button
        $this->getElement('submit')->setDecorators(array('ViewHelper'));

        // Form Decorators
        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'div', 'class' => 'contentColumnLeft')),
            array('Form')
        ));
    }
    //================================================================================

}

